package com.spancer.contentcenter.test.event;

import java.util.ArrayList;
import java.util.List;

/**
 * author by: mars
 * Date: 2020/10/10 15:08
 * Description:
 */
public abstract class AbstractEventMulticaster implements EventMultiCaster{

    private List<WeatherListener> listenerList = new ArrayList<>();
    @Override
    public void multicastEvent(WeatherEvent event) {
        // 定义模板方法
        doStart();
        // 触发监听器
        listenerList.forEach(x->x.onWeatherEvent(event));
        doEnd();
    }

    abstract void doEnd();

    abstract void doStart();

    @Override
    public void addListener(WeatherListener listener) {
        // 添加监听器
        listenerList.add(listener);
    }

    @Override
    public void removeListener(WeatherListener listener) {
        // 移除监听器
        listenerList.remove(listener);
    }
    
    
}
